package com.ls.service.storageRecord;

import com.ls.dao.storageRecord.StorageRecordMapper;
import com.ls.pojo.StorageRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 供货单业务层实现
 */
@Service
public class StorageRecordServiceImpl implements StorageRecordService {
	@Resource
	private StorageRecordMapper storageRecordMapper;

	@Override
	public List<StorageRecord> getList(String supName, Integer supplierId,Integer payStatus
			, Integer currentPageNo, Integer pageSize)throws Exception {
		currentPageNo = (currentPageNo-1)*pageSize;
		return storageRecordMapper.selectList(supName, supplierId, payStatus, currentPageNo, pageSize);
	}

	@Override
	public int getCount(String supName, Integer supplierId,
			Integer payStatus) throws Exception {
		return storageRecordMapper.selectCount(supName, supplierId, payStatus);
	}

	@Override
	public boolean add(StorageRecord storageRecord) throws Exception {
		boolean flag = false;
		storageRecord.setCreatedTime(new Date());
		if(storageRecordMapper.add(storageRecord) > 0)
			flag = true;
		return flag;
	}

	@Override
	public StorageRecord getById(Integer id) throws Exception {
		return storageRecordMapper.selectById(id);
	}

	@Override
	public boolean update(StorageRecord storageRecord) throws Exception {
		boolean flag = false;
		storageRecord.setUpdatedTime(new Date());
		if(storageRecordMapper.update(storageRecord) > 0)
			flag = true;
		return flag;
	}

	@Override
	public boolean deleteById(Integer delId) throws Exception {
		boolean flag = false;
		if(storageRecordMapper.deleteById(delId) > 0)
			flag = true;
		return flag;
	}
}
